//
//  TFDisableChatCell.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2022/3/10.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFDisableChatCell: UITableViewCell {
    @objc public var bgView:UIView!
    @objc public var nameLab:UILabel!

    @objc public var model:TFDisableChatModel?
    {
        didSet
        {
            if (model != nil)
                
            {
                self.setModelUI(model: model!)
            }
        }
    }

    //yes 横屏; no 竖屏
    @objc public var isOrientationLandscape:Bool = false
   

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.bgView = UIView.init()
   
        self.bgView.backgroundColor = UIColor.white
        self.bgView.layer.cornerRadius = 14;
        self.bgView.layer.masksToBounds = true;
        self.contentView.addSubview(self.bgView)
      
        
        self.nameLab = UILabel.init()
        self.nameLab.textColor = UIColor(red: 5/255.0, green: 211/255.0, blue: 128/255.0, alpha: 1.0)
    
        self.nameLab.font = UIFont.PingFang(size: 14)
        self.nameLab.numberOfLines = 0;
        self.nameLab.lineBreakMode = .byCharWrapping
        self.bgView.addSubview(self.nameLab)
      
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setModelUI(model:TFDisableChatModel) {
        var y = 8

        if (self.isOrientationLandscape) {
            y = 4;
        } else {
            y = 8;
        }
        
        if (model.isAll) {
            if (model.disableAllChat) {
                self.nameLab.text = "已开启全体禁言";
            } else {
                self.nameLab.text = "已关闭全体禁言";
            }
            self.bgView.frame = CGRect(x: 12, y: y, width: 130, height: 32)
            self.nameLab.frame = CGRect(x: 16, y: 6, width: 100, height: 20)
            
        } else {
            if (model.disableChat) {
                self.nameLab.text = "你已被禁言";
                self.bgView.frame = CGRect(x: 12, y: y, width: 102, height: 32)
                self.nameLab.frame = CGRect(x: 16, y: 6, width: 70, height: 20)
            } else {
                self.nameLab.text = "你已被取消禁言";
                self.bgView.frame = CGRect(x: 12, y: y, width: 130, height: 32)
                self.nameLab.frame = CGRect(x: 16, y: 6, width: 100, height: 20)
            
        }
      
    }
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
